import psycopg2
conn = psycopg2.connect(dbname="postgres",
                            user="tom",
                            password="gauss@123",
                            host="192.168.116.128",
                            port="26000")
conn.set_client_encoding('utf8')
cur = conn.cursor()

# 删除已存在的表
cur.execute("DROP TABLE IF EXISTS book_user;")

# 创建新表
cur.execute(
'''
CREATE TABLE book_user(
    userid          TEXT PRIMARY KEY    NOT NULL,
    username        TEXT    NOT NULL,
    password        TEXT    NOT NULL,
    phone           TEXT  ,
    status          TEXT  ,
    lend_num        TEXT  ,  
    max_num         TEXT  );
''')
# 数据插入
cur.execute("INSERT INTO book_user (userid,username,password,phone,status,lend_num,max_num) \
      VALUES ('2000300410', '王大锤','123', '1234567', '在借', '1' , '9')")

# 提交更改并关闭连接
conn.commit()
cur.close()
conn.close()

